package main

import "github.com/gin-gonic/gin"

type UserInfo struct {
	Name string
	Age  int
	sex  bool
}

func main() {
	router := gin.Default()
	router.POST("/", func(c *gin.Context) {
		var userInfo UserInfo
		//json转对象
		err := c.ShouldBindJSON(&userInfo)
		//query转对象
		//err := c.ShouldBindQuery(&userInfo)
		if err != nil {
			c.JSON(200, gin.H{"msg": "xxx"})
		}
		c.JSON(200, userInfo)
	})

	router.POST("/form", func(c *gin.Context) {
		var userInfo UserInfo
		//form转对象
		err := c.ShouldBind(&userInfo)
		if err != nil {
			c.JSON(200, gin.H{"msg": "xxx"})
		}
		c.JSON(200, userInfo)
	})
	router.Run(":80")
}
